#-*- coding: utf-8 -*-
'''
Created on Aug 24, 2012

@author: bbg
'''

from sqlalchemy import Integer, Column, MetaData, Table,String
from sqlalchemy.orm import mapper

class UserRight(object):
    '''
    用户权限信息
    '''
    
    _Mapper_ = None
    _company_id_ = -1

    def __init__(self):
        self.user_id = 0
        self.right_name =''
        
    
    @staticmethod
    def doMapping(company_id):
        '''
        按company_id分库，每次生成对象前都要执行一次，以便map到正确的数据库上去
        '''
        if UserRight._company_id_ == company_id:
            return
            
        if UserRight._Mapper_ is not None:
            UserRight._Mapper_.dispose()
            
        metaData = MetaData()
        tableDefine = Table('user_right', metaData,
                           Column('id', Integer, primary_key = True),
                           Column('user_id', Integer),
                           Column('right_name', String), schema = "company_%s" % company_id)
                
        UserRight._Mapper_ = mapper(UserRight, tableDefine)
        
